package com.zlf.mvc.config;

import com.zlf.entity.Admin;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

import java.util.List;

/**
 * @author ：张利锋
 * @date ：Created in 2020/11/22 16:16
 * @description： 扩展 User 类
 * 创建 SecurityAdmin 对象时调用构造器，传入 originalAdmin 和 authorities
 * 可以通过 getOriginalAdmin()方法获取原始 Admin 对象
 * @version: 1.0
 */
public class SecurityAdmin extends User {

    private Admin originalAdmin;
    /**
     * create by: 张利锋
     * description: 传入原始的admin，和角色，权限的信息集合
     * create time: 2020/11/22 16:21
     * @params :[admin, authorities]
     * @return
     */
    public SecurityAdmin(Admin admin, List<GrantedAuthority> authorities) {
        super(admin.getLoginAcct(), admin.getUserPswd(), authorities);
        this.originalAdmin=admin;
        //擦除原始对象密码
        this.originalAdmin.setUserPswd(null);
    }

    public Admin getOriginalAdmin() {
        return originalAdmin;
    }
}
